package com.darthsith.droidathome.mobile;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.web.client.RestTemplate;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AddUserActivity extends Activity implements OnClickListener {
	
	private EditText username;
	private EditText password;
	private Button ok;
	private TextView result;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.adduser);
		username=(EditText)findViewById(R.id.username);
		password=(EditText)findViewById(R.id.password);
		ok=(Button)findViewById(R.id.ok);
		result=(TextView)findViewById(R.id.result);
		ok.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.getId()==ok.getId()) {
			String url="http://192.168.81.78:8180/droid-at-home-0.1/addDevice";
			RestTemplate restTemplate=new RestTemplate();
			Device device=new Device("911", "galaxy");
			restTemplate.postForObject(url, device, Boolean.class);
//			HttpClient client=new DefaultHttpClient();
//			String uri="http://192.168.81.56:8080/droid-at-home-0.1/addDevice&mac="+username.getText().toString().trim()+"&name="+password.getText().toString().trim();
//			HttpGet get=new HttpGet(uri);
//			try {
//				HttpResponse response=client.execute(get);
//				String str=EntityUtils.toString(response.getEntity());
//				result.setText("Command: "+uri+"\nDONE");
//			} catch (ClientProtocolException e) {
//				e.printStackTrace();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
		}
	}

}
